<!doctype html>
<html class="no-js">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Admin</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="renderer" content="webkit">
  <link rel="stylesheet" href="css/amazeui.min.css"/>
  <link rel="stylesheet" href="css/admin.css">
</head>
<body><?php 
include 'c.php';
if (isset($_GET['p'])) {
    $page=$_GET['p'];
}else{
    $page=1;
}
$pageSize=20;

$thetag='all';
if (isset($_GET['tag'])){
    $thetag=$_GET['tag'];
}

$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
if (!$mysqli->set_charset("utf8")) {printf("Error loading character set utf8: %s\n", $mysqli->error);}
$query=$mysqli->query("SELECT tag FROM analyse group by tag ");
$tagName=array();
while ($list=$query->fetch_assoc()){
    $tagName[]=$list['tag'];
}


?><header class="am-topbar am-topbar-inverse admin-header">
  <div class="am-topbar-brand">
    <strong>邮件</strong> <small>统计</small>
  </div>
 
  <div class="am-collapse am-topbar-collapse" id="topbar-collapse">

    <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list">
      <li class="am-dropdown" data-am-dropdown>
        <a class="am-dropdown-toggle" data-am-dropdown-toggle href="javascript:;">
          <span class="am-icon-users"></span> 管理员 <span class="am-icon-caret-down"></span>
        </a>
        <ul class="am-dropdown-content">
          <li><a href="#"><span class="am-icon-power-off"></span> 退出</a></li>
        </ul>
      </li>
      <li class="am-hide-sm-only"><a href="javascript:;" id="admin-fullscreen"> </a></li>
    </ul>
  </div>
</header>

<div class="am-cf admin-main">
 

  <!-- content start -->
  <div class="admin-content">
    <div class="admin-content-body">
      <div class="am-cf am-padding am-padding-bottom-0">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">邮件</strong> / <small>数据</small></div>
      </div>

      <hr>

      <div class="am-g">
        <div class="am-u-sm-12 am-u-md-6">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
              <button id="goDown" type="button" class="am-btn am-btn-default"><span class="am-icon-save"></span> 保存</button>
            </div>
          </div>
        </div>
        <div class="am-u-sm-12 am-u-md-3">
          <div class="am-form-group">
            <select id="taglei">
              <option value="all">所有类别</option>
              <?php foreach ($tagName as $tag){ 
                  $select='';
                  if ($thetag == $tag){
                      $select='selected="selected"';
                  }
                  
               ?>
          
              <option value="<?php echo $tag; ?>" <?php echo $select; ?>><?php echo $tag; ?></option>
              <?php } ?>
            </select>
          </div>
        </div>
         
      </div>

      <div class="am-g">
        <div class="am-u-sm-12">
          <form class="am-form">
            <table class="am-table am-table-striped am-table-hover table-main">
              <thead>
              <tr>
              <th class="table-id">ID</th><th class="table-title">uid</th>
              <th class="table-type">ip</th><th class="table-author am-hide-sm-only">tag</th><th class="table-date am-hide-sm-only">客户端</th><th class="table-set">时间</th>
              </tr>
              </thead>
              <tbody>
              <?php 
              if ($thetag != 'all'){
                  $sql="select count(id) as count from analyse where tag='".$thetag."' ";
              }else{
                  $sql="select count(id) as count from analyse ";
              }
              $query_count = $mysqli->query($sql);
              $row=$query_count->fetch_array();
              $total=$row['count'];
              $total_page=1;
              if ($total) {
                  if($total % $pageSize){
                      $total_page=(int)($total/$pageSize)+1;
                  }else{
                      $total_page=($total/$pageSize);
                  }
              }
 
              $pageUrl='?tag='.$thetag.'&p=';
              
              
              if ($thetag != 'all'){
                  $sql="SELECT id,uid,ip,tag,detail,createtime FROM analyse where tag='".$thetag."' order by id desc limit ".($page-1)*$pageSize.", $pageSize ";
              }else{
                  $sql="SELECT id,uid,ip,tag,detail,createtime FROM analyse order by id desc limit ".($page-1)*$pageSize.", $pageSize ";
              }
              
              $query=$mysqli->query($sql);
             
              while ($list=$query->fetch_assoc()){
              ?>
              <tr>
                <td><?php echo $list['id']; ?></td>
                <td><?php echo $list['uid']; ?></td>
                <td><?php echo $list['ip']; ?></td>
                <td><?php echo $list['tag']; ?></td>
                <td><?php
                $detail=json_decode($list['detail'], true);
 
                $os=$detail['os'];
                $browser=$detail['b'];
                if ('Other' == $detail['os']){
                    $os=$browser='未知';
                }
                ?>系统：<?php echo $os; ?>, <?php if ('未知' != $browser){ ?>浏览器：<?php echo $browser; } ?></td>  
                <td><?php echo $list['createtime']; ?></td>
                
              </tr>
              <?php 
              }
              ?>
              </tbody>
            </table>
            <div class="am-cf">
              共 <?php echo $total; ?> 条记录
              <div class="am-fr">
                <ul class="am-pagination">
                  <?php if (($page-1) > 0){ ?><li><a href="<?php echo $pageUrl,($page-1); ?>">«</a></li><?php } ?>
                  
                  <?php if (($page-2) > 0){ ?><li><a href="<?php echo $pageUrl,($page-2); ?>"><?php echo $page-2; ?></a></li><?php } ?>
                  <?php if (($page-1) > 0){ ?><li><a href="<?php echo $pageUrl,($page-1); ?>"><?php echo $page-1; ?></a></li><?php } ?>
                  <li class="am-active"><a href="<?php echo $pageUrl,$page; ?>"><?php echo $page; ?></a></li>
                  <?php if (($page+1) <=  $total_page){ ?><li><a href="<?php echo $pageUrl,($page+1); ?>"><?php echo $page+1; ?></a></li><?php } ?>
                  <?php if (($page+2) <=  $total_page){ ?><li><a href="<?php echo $pageUrl,($page+2); ?>"><?php echo $page+2; ?></a></li><?php } ?>
                  <?php if (($page+1) <=  $total_page){ ?><li><a href="<?php echo $pageUrl,($page+1); ?>">»</a></li><?php } ?>
                </ul>
              </div>
            </div>
            <hr />
            <p></p>
          </form>
        </div>

      </div>
    </div>

    <br />
  </div>
  <!-- content end -->
</div>

 
 
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<!--[if lt IE 9]>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<script src="js/amazeui.min.js"></script>
<script src="js/app.js"></script>
<script>
$(function(){
    $("#taglei").change(function () {
        var _tag=$("#taglei").val();
        window.location.href="?tag="+_tag;
        console.log(_tag);
        
     });

    $("#goDown").click(function(){
        window.location.href="data2.php?tag=<?php echo $thetag; ?>";
   });
});
</script>
</body>
</html>
